import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.ukui.quick.widgets 1.0
import org.ukui.quick.items 1.0
import QtQuick.Controls 2.15
import QtQuick.Controls 2.15 as Controls

WidgetItem {
    id: rootWidget
    width: 410
    height: 40

    RowLayout {
        anchors.centerIn: parent
        spacing: 10

        TextField {
            id: decimalInput
            width: 200
            placeholderText: "输入十进制数"
            validator: RegExpValidator { regExp: /^[0-9]+$/ }
        }

        Button {
            text: "转换"
            width: 50
            onClicked: {
                var decimalString = decimalInput.text;
                var decimalNumber = parseInt(decimalString, 10);
                binaryOutput.text = isNaN(decimalNumber) ? "无效" : decimalNumber.toString(2);
            }
        }

        Text {
            id: binaryOutput
            width: 60 // 调整宽度以适应横向布局
            horizontalAlignment: Text.AlignHCenter
            font.pixelSize: 20
        }
    }
}
